LevelEvents.tick(event => {
    let { level } = event;
    // 初始化天数计数器，如果不存在则设置为0
    if (!level.persistentData.bossSpawnDayCounter) {
        level.persistentData.bossSpawnDayCounter = 0;
    }
    
    // 检查是否是新的一天且维度是否是主世界
    if (level.dayTime() === 1000) { 
        // 每天递增计数器
        level.persistentData.bossSpawnDayCounter++;
        
        // 取余操作，这里设置为每3天生成一次BOSS
        // 可以修改3为其他数字来调整生成频率
        if (level.persistentData.bossSpawnDayCounter % 1 === 0) {
            // 新建一个实体 
            let husk = level.createEntity('cataclysm:the_prowler');
            husk.setPosition(520, 79, 2280);   
            husk.mergeNbt({ NoAI: false });
            husk.mergeNbt({ DeathLootTable: "" });
            husk.spawn(); 

            // 新建第二大陆BOSS 
            let husk2 = level.createEntity('cataclysm:kobolediator');
            husk2.setPosition(5600, 77, 3096);   
            husk2.mergeNbt({ NoAI: false });
            husk2.mergeNbt({ DeathLootTable: "" });
            husk2.spawn(); 

            // 冥行武弁
            let husk3 = level.createEntity('cataclysm:aptrgangr')
            husk3.setPosition(4568, 214, -2016)
            husk3.mergeNbt({ NoAI: false });
            husk3.mergeNbt({ DeathLootTable: "" });
            husk3.spawn(); 

            // 远古遗魂
            let husk4 = level.createEntity('cataclysm:ancient_remnant')
            husk4.setPosition(4824, 313, 1056)
            husk4.mergeNbt({ NoAI: false });
            husk4.mergeNbt({ DeathLootTable: "" });
            husk4.spawn(); 

            // 先驱者
            let husk5 = level.createEntity('cataclysm:the_harbinger')
            husk5.setPosition(1832, 67, -2704)
            husk5.mergeNbt({ NoAI: false });
            husk5.mergeNbt({ DeathLootTable: "" });
            husk5.spawn(); 

            // Maledictus
            let husk6 = level.createEntity('cataclysm:maledictus')
            husk6.setPosition(304, 104, -1233)
            husk6.mergeNbt({ NoAI: false });
            husk6.mergeNbt({ DeathLootTable: "" });
            husk6.spawn();

            // Ignited Revenant
            let husk7 = level.createEntity('cataclysm:ignited_revenant')
            husk7.setPosition(-3093, 95, -3494)
            husk7.mergeNbt({ NoAI: false });
            husk7.mergeNbt({ DeathLootTable: "" });
            husk7.spawn();

            // 下届合金巨兽
            let husk8 = level.createEntity('cataclysm:netherite_monstrosity')
            husk8.setPosition(-2613, 181, 1634)
            husk8.mergeNbt({ NoAI: false });
            husk8.mergeNbt({ DeathLootTable: "" });
            husk8.spawn();

            // 焰魔
            let husk9 = level.createEntity('cataclysm:ignis')
            husk9.setPosition(-2400, 164, 4104)
            husk9.mergeNbt({ NoAI: false });
            husk9.mergeNbt({ DeathLootTable: "" });
            husk9.spawn();

            // 末影傀儡
            let husk10 = level.createEntity('cataclysm:ender_golem')
            husk10.setPosition(-288, 107, 3888)
            husk10.mergeNbt({ NoAI: false });
            husk10.mergeNbt({ DeathLootTable: "" });
            husk10.spawn();

            // 末影守卫
            let husk11 = level.createEntity('cataclysm:ender_guardian')
            husk11.setPosition(1449, 81, 5846)
            husk11.mergeNbt({ NoAI: false });
            husk11.mergeNbt({ DeathLootTable: "" });
            husk11.mergeNbt({ Armor: 0 });
            husk11.spawn();
            
            event.server.runCommandSilent(`say 第${level.persistentData.bossSpawnDayCounter}天，BOSS已生成！`);
        } else {
            event.server.runCommandSilent(`say 第${level.persistentData.bossSpawnDayCounter}天，今日无BOSS生成`);
        }
    } 
    
    // 每天午夜清除BOSS，防止堆积
    if(level.dayTime() === 24000){
         event.server.runCommandSilent('kill @e[type=cataclysm:the_prowler]')
         event.server.runCommandSilent('kill @e[type=cataclysm:kobolediator]')
         event.server.runCommandSilent('kill @e[type=cataclysm:aptrgangr]')
         event.server.runCommandSilent('kill @e[type=cataclysm:ancient_remnant]')
         event.server.runCommandSilent('kill @e[type=cataclysm:the_harbinger]')
         event.server.runCommandSilent('kill @e[type=cataclysm:maledictus]')
         event.server.runCommandSilent('kill @e[type=cataclysm:ignited_revenant]')
         event.server.runCommandSilent('kill @e[type=cataclysm:netherite_monstrosity]')
         event.server.runCommandSilent('kill @e[type=cataclysm:ignis]')
         event.server.runCommandSilent('kill @e[type=cataclysm:ender_golem]')
         event.server.runCommandSilent('kill @e[type=cataclysm:ender_guardian]')
         // 同时清理掉落物
         event.server.runCommandSilent('kill @e[type=item]')
         event.server.runCommandSilent('say 神秘降至，诅咒让一切湮灭！同时还清理了掉落物');
    }
})
